<template>
  <div>
    <button class="vue-button" :class="classes" :disabled="disabled">
      <span v-if="loading" class="vue-loadingIndicator"></span>
      <slot />
    </button>
  </div>
</template>
<script lang="ts">
import { computed } from "vue";
export default {
  props: {
    theme: {
      value: String,
      default: "button",
    },
    size: {
      type: String,
      default: "normal",
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    loading: {
      type: Boolean,
      default: false,
    },
  },
  setup(props) {
    const { theme, size } = props;
    const classes = computed(() => {
      return { [`vue-theme-${theme}`]: theme, [`vue-size-${size}`]: size };
    });
    return { classes };
  },
};
</script>
<style lang="scss">
$h: 32px;
$border-color: #d9d9d9;
$color: #333;
$blue: #40a9ff;
$grey: grey;
$radius: 4px;
.vue-button {
  box-sizing: border-box;
  height: $h;
  padding: 0 12px;
  margin:10px;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  background: white;
  color: $color;
  border: 1px solid $border-color;
  border-radius: $radius;
  box-shadow: 0 1px 0 fade-out(black, 0.95);
  position: relative;
  & + & {
    margin-left: 8px;
  }
  &:hover,
  &:focus {
    color: $blue;
    border-color: $blue;
  }
  &:focus {
    outline: none;
  }
  &::-moz-focus-inner {
    border: 0;
  }
  &.vue-theme-text {
    border: none;
    background: none;
    box-shadow: none;
  }
  &.vue-theme-link {
    border: none;
    background: none;
    box-shadow: none;
    color: $blue;
  }
  &.vue-theme-primary {
    border: none;
    background: $blue;
    color: #fff;
  }
  &.vue-theme-button {
    position: relative;
    &.vue-size-small {
      font-size: 12px;
      height: 24px;
    }
    &.vue-size-medium {
      font-size: 18px;
      height: 36px;
    }
    &.vue-size-big {
      font-size: 24px;
      height: 48px;
    }
    &[disabled] {
      cursor: not-allowed;
      color: $grey;
      border-color: #f5f5f5;
      background: $border-color;
    }

    > .vue-loadingIndicator {
      width: 10px;
      height: 10px;
      display: inline-block;
      margin-right: 8px;
      border-radius: 50%;
      border-color: $blue $blue $blue transparent;
      border-style: dashed;
      border-width: 1px;
      animation: vue-spin 1s infinite linear;
      position: absolute;
      top: 40%;
      right:65%;
    }
  }
}

@keyframes vue-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
</style>